/*
   Copyright 2012 Jason Drake (jadrake75@gmail.com)
 
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.javad.components;

import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.prefs.Preferences;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class ComponentResources {
	
	private static final String MESSAGE_NAME = "org.javad.components.componentsMessage"; //$NON-NLS-1$
	private static final String IMAGE_NAME = "org.javad.components.componentsIcons"; //$NON-NLS-1$
	
	private static final ResourceBundle IMAGE_BUNDLE = ResourceBundle.getBundle(IMAGE_NAME);
	private static final ResourceBundle MESSAGE_BUNDLE = ResourceBundle.getBundle(MESSAGE_NAME);
	
	private ComponentResources() {
	}
	
	public static String getString(String key) {
		try {
			return MESSAGE_BUNDLE.getString(key);
		} catch (MissingResourceException e) {
			return '!' + key + '!';
		}
	}
	
	public static String getIconName( String key ) {
		try {
			return IMAGE_BUNDLE.getString(key);
		} catch(MissingResourceException e ) {
			return '!' + key + '!';
		}
	}
	
	
	public static Icon getIcon(String key) {
		return new ImageIcon( ComponentResources.class.getResource(getIconName(key)));
	}
	
	public static Preferences getPreferencesNode() {
		return Preferences.userNodeForPackage(ComponentResources.class);
	}
}
